<% layout('/layouts/default.html', {title: '任务部署信息表(主)管理', libs: ['validate','fileupload','dataGrid']}){ %>
<style>
	.lhTime .select2-container{
		width: 60% !important;
		margin-left: 10px;
		margin-right: 10px;
	}
	#table2 tr{
		padding-bottom: 10px;
		display: block;
	}
	.addku{
		position: absolute;
		width: 30px;
		border: 1px solid #d3d4d6;
		text-align: center;
		height: 30px;
		line-height: 30px;
		border-radius: 4px;
		margin-left: 5px;
	}
	.border{
		position: relative;
		margin-left: 0px!important;
		padding: 10px 0px !important;
		background: url('${ctxStatic}/m/images/bgc.png') no-repeat 120% 100%;
		margin-bottom: 10px!important;
		background-size: 92% 100%;
	}
	.wow {
		margin: 0px 0px 0px -15px!important;
		padding: 0 10px;
	}
	.ss{
		text-align: center;
		border-radius: 50%;
		position: absolute;
		top: 30px;
		margin-top: -1px;
		left: 6%;
		margin-left: 0.133333rem;
		width: 1.786667rem;
		height: 20px;
		background-color: #d3d4d6;
	}
	.fromBox{
		position: relative;
	}
	.btn1{
		text-align: center;
		top: 33px;
		position: absolute;
		margin-top: -1px;
		left: 7.5%;
		margin-left: 0.133333rem;
		width: 1.786667rem;
		height: 20px;
		transform: scale(1.2);

	}
	.btn1:hover{
		color: red;
		cursor: pointer;
	}
	.btn1 i{
		width: 100%;
		height: 100%;
	}

	.hideUnit{
		display: none !important;
	}

	#taskLeaderOrg1Div{
		display: none !important;
	}
	#taskLeaderOrg2Div{
		display: none !important;
	}
	#taskLeaderOrg3Div{
		display: none !important;
	}
	#taskLeaderOrg4Div{
		display: none !important;
	}
	#taskLeaderOrg5Div{
		display: none !important;
	}

	.form-control[disabled], .form-control[readonly], fieldset[disabled] .form-control {
		background-color: #FFFFFF;
	}
</style>
<div class="main-content">
	<div class="box box-main">
		<#form:form id="inputForm" model="${dcSupTaskInfo}" action="${ctx}/taskdeploy/dcSupTaskInfo/batchSave" method="post" class="form-horizontal">
		<div class="box-body">
			<div class="form-unit">${text('基本信息')}</div>
			<div class="row">
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
						</label>
						<div class="col-sm-8">
							<#form:hidden path="isNewRecord"/>
							<#form:hidden path="normalFlag"/>
							<#form:hidden path="remarks4"/>
							<#form:hidden path="id" maxlength="64" readonly="${!dcSupTaskInfo.isNewRecord}" class="form-control"/>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('任务年度')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8">
							<#form:select path="taskYear" items="${yearList}" blankOption="true" data-placeholder="请选择" itemLabel="yearLabel" itemValue="yearValue" class="form-control width-120 required"
							defaultValue="${currentYear}"/>
						</div>
					</div>
				</div>
				<div class="col-xs-6">
					<div class="form-group">
						<label class="control-label col-sm-4" title="">
							<span class="required ">*</span> ${text('任务类型')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-8" style="padding-right: 50px;position: relative">
							<#form:select path="taskTypeCode" items="${dicts}" blankOption="true" data-placeholder="请选择任务类型" itemLabel="dictLabel" itemValue="dictValue" class="form-control width-120 required" defaultValue='101'/>
							<#form:hidden path="taskTypeName"/>
							<#form:hidden path="taskStatus"/>
							<% if(hasRole('SUPLEADER') || @UserUtils.getUser().getUserCode() == 'system'){ %>
							<a onclick="addTab()" class="addku" style="position: absolute"><i class="fa fa-plus"> </i></a>
							<% } %>
						</div>
						<!--<div class="col-sm-1" style="border: blue;">-->
						<!--	<a onclick="addTab()"><i class="fa fa-plus"> </i></a>-->
						<!--</div>-->
					</div>
				</div>
				<div class="col-xs-12">
					<div class="form-group">
						<label class="control-label col-sm-2" title="">
							<span class="required ">*</span> ${text('任务标题')}：<i class="fa icon-question hide"></i></label>
						<div class="col-sm-10">
							<#form:textarea path="taskTitle" rows="2" class="form-control required " autocomplete="off" placeholder="任务标题，限制200字以内" maxlength="200"/>
						</div>
					</div>
				</div>
			</div>
		</div>

		<div class="row contant wow">
			<div id="formCode1"  class="wow1" style="margin-top: -10px;">
				<% include('/modules/task/deploy/addFormCode.html'){} %>
			</div>
			<div id="formCode2"  class="fromBox" style="display: none">
				<% include('/modules/task/deploy/addFormCode2.html'){} %>
				<a class="btn1 " onclick="delete1(2)"><i class="glyphicon glyphicon-remove-sign"></i> </a>
			</div>
			<div id="formCode3" class="fromBox" style="display: none">
				<% include('/modules/task/deploy/addFormCode3.html'){} %>
				<a class="btn1 " onclick="delete1(3)"><i class="glyphicon glyphicon-remove-sign"></i> </a>
			</div>
			<div id="formCode4" class="fromBox" style="display: none">
				<% include('/modules/task/deploy/addFormCode4.html'){} %>
				<a class="btn1 " onclick="delete1(4)"><i class="glyphicon glyphicon-remove-sign"></i> </a>
			</div>
			<div id="formCode5" class="fromBox" style="display: none">
				<% include('/modules/task/deploy/addFormCode5.html'){} %>
				<a class="btn1 " onclick="delete1(5)"><i class="glyphicon glyphicon-remove-sign"></i> </a>
			</div>
			<#form:hidden path="formCount" value="1"/>
		</div>

		<div class="row">
			<div class="row">
				<div class="col-xs-12">
					<div class="form-group">
						<label class="control-label col-sm-2">
						</label>
						<div class="col-sm-10 ">
							<a class="btn btn-primary btn-sm mt10 mb10 goon"><i class="fa fa-plus"></i> 继续添加</a>
						</div>
					</div>
				</div>
			</div>

		</div>
		<div class="row">
			<div class="col-xs-6">
				<div class="form-group">
					<label class="control-label col-sm-4" title="">
						<span class="required">*</span> ${text('督办字号')}：<i class="fa icon-question hide"></i></label>
					<div class="col-sm-8">
						<div style="width: 60%;float:left;">
							<#form:select path="msgNum" dictType="dc_num_secret" blankOption="false" onchange ="changeOne()" class="form-control"/>
						</div>
						<div style="width: 40%;float:left;padding-left: 2px;">
							<#form:input path="msgNum2" maxlength="100" value="${dcSupTaskInfo.messageNumber}" placeholder="督办字号"  maxlength="10" min="1" class="form-control digits required"/>
							<#form:hidden path="messageNumber"/>
							<#form:hidden path="formFlag" defaultValue="0"/>
						</div>
					</div>
				</div>
			</div>


			<div class="col-xs-6">
				<div class="form-group">
					<label class="control-label col-sm-4" title="">
						<span class="required hide">*</span> ${text('反馈附件必填')}：<i class="fa icon-question hide"></i></label>
					<div class="col-sm-6">
						<#form:radio path="attachmentFlag" dictType="dc_feedback_file" class="form-control" defaultValue="0"/>
					</div>
				</div>
			</div>
			<div class="col-xs-6" id="auditDiv">
				<div class="form-group">
					<label class="control-label col-sm-4" title="">
						<span class="required">*</span> 审核人：<i class="fa icon-question hide"></i></label>
					<div class="col-sm-8">
						<#form:select id="auditorCode" path="auditorCode" items="${auditorUserList!}"  blankOption="true" data-placeholder="请选择审核人" itemLabel="userName" itemValue="userCode" class="form-control width-120 required" />
						<#form:hidden id="auditorName" path="auditorName" />
					</div>
				</div>
			</div>
		</div>
		<div class="row">
			<div class="col-xs-12">
				<div class="form-group">
					<label class="control-label col-sm-2">
						<span class="required hide">*</span> ${text('附件上传')}：</label>
					<div class="col-sm-10">
						<#form:fileupload id="uploadFile" bizKey="${dcSupTaskInfo.id}" bizType="dcSupTaskInfo_file"
						uploadType="all" class="" readonly="false" preview="true" maxUploadNum="10"/>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div class="box-footer">
		<div class="row">
			<div class="col-sm-offset-2 col-sm-10">
				<% if (hasPermi('taskdeploy:dcSupTaskInfo:edit')){ %>
				<% if(dcSupTaskInfo.taskStatus != '' && dcSupTaskInfo.taskStatus != '2'){ %>
				<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit" onclick="changeStatus(2);"><i class="fa fa-check"></i> ${text('立即发布')}</button>&nbsp;
				<% } %>
				<% if(dcSupTaskInfo.id == '' || dcSupTaskInfo.id == null){ %>
				<button type="submit" class="btn btn-sm btn-default" id="btnSubmit2" onclick="changeStatus(1);"><i class="fa fa-save"></i> ${text('存为草稿')}</button>&nbsp;
				<% } %>
				<% } %>
				<button type="button" class="btn btn-sm btn-default btnList" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
			</div>
		</div>
	</div>
</#form:form>
</div>
</div>
<% } %>

<script>
	//动态添加行
	//打开新的标签
	/*切换反馈方式同步切换反馈频次数据*/
	var weekData = [{ id: 1, text: '周一' }, { id: 2, text: '周二' }, { id: 3, text: '周三' }, { id: 4, text: '周四' }, { id: 5, text: '周五' }, { id: 6, text: '周六' }, { id: 7, text: '周日' }];
	var monthData = [{ id: 1, text: '1' }, { id: 2, text: '2' }, { id: 3, text: '3' }, { id: 4, text: '4' },
		{ id: 5, text: '5' }, { id: 6, text: '6' }, { id: 7, text: '7' }, { id: 8, text: '8' }, { id: 9, text: '9' },
		{ id: 10, text: '10' }, { id: 11, text: '11' }, { id: 12, text: '12' }, { id: 13, text: '13' }, { id: 14, text: '14' },
		{ id: 15, text: '15' }, { id: 16, text: '16' }, { id: 17, text: '17' }, { id: 18, text: '18' }, { id: 19, text: '19' },
		{ id: 20, text: '20' }, { id: 21, text: '21' }, { id: 22, text: '22' }, { id:23, text: '23' }, { id: 24, text: '24' },
		{ id: 25, text: '25' }, { id: 26, text: '26' }, { id: 27, text: '27' }, { id:28, text: '28' },{ id:29, text: '29' },{ id:30, text: '30' },{ id:31, text: '31' }];
	$(function () {
		feedbackCircle(1)
		feedbackCircle(2)
		feedbackCircle(3)
		feedbackCircle(4)
		feedbackCircle(5)
	})

	function addTab(type) {
		js.addTabPage(null, "任务类型管理", "${ctx}/dict/dcSupTaskInfoDict" , true);
	}

</script>

<script>

	// $.extend($.validator,{defaults:{ignore:""}});
	// 继续添加？


	var formCount=1;
	$("#formCount").val(formCount);




	function delete1(v){
		$('#formCode'+v).hide()
		$('.wow').append(
				$('#formCode'+v)
		)
		$('.wow').append(
				$('#formCount')
		)
		//内容
		$('#taskContent'+v).val('')
		//开始时间
		$('#taskStartTime'+v).val('')
		//结束时间
		$('#taskEndTime'+v).val('')
		//协同单位（名称）
		$('#'+'taskCoopOrg'+v+'Name').val('')
		//协同单位（ID）
		$('#'+'taskCoopOrg'+v+'Code').val('')
		//督办人
		$('#taskSupUser'+v).val('').select2()
		//督办科室
		$('#taskSupOrg'+v).val('').select2()
		//牵头领导
		$('#taskLeader'+v).val('').select2()
		//牵头责任单位(名称)
		$('#'+'taskLeaderOrg'+v+'Name').val('')
		//牵头责任单位(ID)
		$('#'+'taskLeaderOrg'+v+'Code').val('')
		//联系电话
		$('#contactPhone'+v).val('')
		//排序编号
		$('#sortNum'+v).val('')
		//反馈时间要求
		$('#feedbackWay'+v).val('').select2()
		//(具体时间)
		$('#feedbackRate'+v).val('').select2()

		// $('#taskLeaderOrg2Name').val('')
		$('#scheBusiTaskFeedbackDataGrid'+v ).children().html('')
		// $('#taskLeader2 ').val('').select2()
		// $('#contactPhone2').val('')
		// $('#sortNum2').val('')
		//
		//
		// $('#feedbackRate2').val('').select2()



		formCount--


		$('.ss').remove()
		$('.border').eq(0).append(
				'<span class="ss">'+
				'1'+
				'</span>'
		)
		$('.border').eq(1).append(
				'<span class="ss">'+
				'2'+
				'</span>'
		)
		$('.border').eq(2).append(
				'<span class="ss">'+
				'3'+
				'</span>'
		)
		$('.border').eq(3).append(
				'<span class="ss">'+
				'4'+
				'</span>'
		)
		$('.border').eq(4).append(
				'<span class="ss">'+
				'5'+
				'</span>'
		)

		$("#formCount").val(formCount);

	}



	function fuzhi(){
		var fznum=$('.fromBox').eq(formCount-2).attr('id').substring(8)
		if (fznum=='2'){
			$('#taskStartTime2').val($('#taskStartTime1').val())
			$('#feedbackWay2').select2('val', '4');
		}
		if (fznum=='3'){
			$('#taskStartTime3').val($('#taskStartTime1').val())
			$('#feedbackWay3').select2('val', '4');
		}
		if (fznum=='4'){
			$('#taskStartTime4').val($('#taskStartTime1').val())
			$('#feedbackWay4').select2('val', '4');
		}
		if (fznum=='5'){
			$('#taskStartTime5').val($('#taskStartTime1').val())
			$('#feedbackWay5').select2('val', '4');
		}
	}

	$('.goon').click(function () {




		formCount++

		if (formCount==2){
			fuzhi()



			$('.digits').eq(0).val(Number($('#sortNum1').val()))
			$('.digits').eq(1).val(Number($('#sortNum1').val())+1)


			$('.ss').remove()
			$('.border').eq(0).append(
					'<span class="ss">'+
					'1'+
					'</span>'
			)
			$('.border').eq(1).append(
					'<span class="ss">'+
					'2'+
					'</span>'
			)


		}
		if (formCount==3){
			fuzhi()

			$('.digits').eq(0).val(Number($('#sortNum1').val()))
			$('.digits').eq(1).val(Number($('#sortNum1').val())+1)
			$('.digits').eq(2).val(Number($('#sortNum1').val())+2)
			// $('#taskStartTime3').val($('#taskStartTime1').val())
			// $('#feedbackWay3').select2('val', '4');
			$('.ss').remove()
			$('.border').eq(0).append(
					'<span class="ss">'+
					'1'+
					'</span>'
			)
			$('.border').eq(1).append(
					'<span class="ss">'+
					'2'+
					'</span>'
			)
			$('.border').eq(2).append(
					'<span class="ss">'+
					'3'+
					'</span>'
			)
		}
		if (formCount==4){
			fuzhi()
			$('.digits').eq(0).val(Number($('#sortNum1').val()))
			$('.digits').eq(1).val(Number($('#sortNum1').val())+1)
			$('.digits').eq(2).val(Number($('#sortNum1').val())+2)
			$('.digits').eq(3).val(Number($('#sortNum1').val())+3)
			// $('#taskStartTime4').val($('#taskStartTime1').val())
			// $('#feedbackWay4').select2('val', '4');
			$('.border').eq(3).append(
					'<span class="ss">'+
					'4'+
					'</span>'
			)
		}
		if (formCount==5){
			fuzhi()
			$('.digits').eq(0).val(Number($('#sortNum1').val()))
			$('.digits').eq(1).val(Number($('#sortNum1').val())+1)
			$('.digits').eq(2).val(Number($('#sortNum1').val())+2)
			$('.digits').eq(3).val(Number($('#sortNum1').val())+3)
			$('.digits').eq(4).val(Number($('#sortNum1').val())+4)
			// $('#taskStartTime5').val($('#taskStartTime1').val())
			// $('#feedbackWay5').select2('val', '4');
			$('.border').eq(4).append(
					'<span class="ss">'+
					'5'+
					'</span>'
			)
		}


		// $(window).resize()
		if (formCount>5){
			formCount=5



			js.showMessage("最多只能添加5个任务内容")
			return
		}
		// $("#formCode"+formCount).show();
		$('.fromBox').eq(formCount-2).show()
		$("#formCount").val(formCount);
	})



	function changeStatus(status) {
		//设置数据状态 2为发布 1为草稿
		if(status==2){
			$("#taskStatus").val('2')
		}
		if(status==1){
			$("#taskStatus").val('1')
		}
		$("#messageNumber").val($("#msgNum").find("option:selected").text()+	$("#msgNum2").val());
		if ($.validator) {
			$.validator.prototype.elements = function () {
				var validator = this,
						rulesCache = {};
				return $([]).add(this.currentForm.elements)
						.filter(":input")
						.not(":submit, :reset, :image, [disabled]")
						.not(this.settings.ignore)
						.filter(function () {
							var elementIdentification = this.id ;
							!elementIdentification && validator.settings.debug && window.console && console.error("%o has no id nor name assigned", this);
							if (elementIdentification in rulesCache || !validator.objectLength($(this).rules()))
								return false;

							rulesCache[elementIdentification] = true;
							return true;
						});
			};

		}
		$("#inputForm").validate({
			ignore: ":hidden",//不验证的元素
			submitHandler: function (form) {
				for(var count=1;count<=formCount;count++){
					$("#taskTypeName").val($("#taskTypeCode").find("option:selected").text());
					$("#taskRequireName"+count).val($("#taskRequireCode"+count).find("option:selected").text());
					$("#taskSupUserName"+count).val($("#taskSupUser"+count).find("option:selected").text());

					$("#taskSupOrgName"+count).val($("#taskSupOrg"+count).find("option:selected").text());
					$("#auditorName").val($("#auditorCode").find("option:selected").text());
					const selectedValueArr = []
					const selectedValueId = []
					for (let i = 0; i < $("#taskLeader"+count).select2("data").length; i++) {
						// 如果该option被选中，则将它的value存入数组
						selectedValueArr.push($("#taskLeader"+count).select2("data")[i].text)
						selectedValueId.push($("#taskLeader"+count).select2("data")[i].id)
					}
					// 如果后端需要字符串形式，比如逗号分隔
					const selectedValueStr = selectedValueArr.join(',')
					const selectedValueIdStr = selectedValueId.join(',')
					$("#taskLeaderName"+count).val(selectedValueStr);
					$("#taskLeader_"+count).val(selectedValueIdStr);

					var dd = $("#scheBusiTaskFeedbackDataGrid"+count).dataGrid('getRowData');
					// if(dd.length==0){
					// 	js.showMessage("反馈开始结束时间不可为空")
					// 	return;
					// }
				}
				js.ajaxSubmitForm($(form), function (data) {
					js.showMessage(data.message);
					if (data.result == Global.TRUE) {
						//设置发布按钮失效
						$('#btnSubmit').attr("disabled",true);
						//设置保存草稿按钮失效
						$('#btnSubmit2').attr("disabled",true);
						js.closeCurrentTabPage(function (contentWindow) {
							contentWindow.page();
						});
					}
				}, "json");
			},

		});

	}

	function feedbackCircle(v){
		if ($("#feedbackWay"+v).val()=='4'){
			$("#feedbackRateShow"+v).css("display","none");
			taskTimeChange(v);
		}
		else if($("#feedbackWay"+v).val()=='3'){
			// $("#feedbackRate"+v).select2('destroy').empty();
			//  $("#feedbackRate"+v).options.selectedIndex = 0
			$("#feedbackRate"+v).select2('destroy').empty();
			$("#feedbackRate"+v).select2({data: weekData,placeholder:'请选择',allowClear:true,})
			$("#feedbackRate"+v).val("").select2({placeholder:'请选择'})
			$("#yearMonth"+v).text('每周：');
			$("#feedbackRateShow"+v).css("display","block");
		}else if($("#feedbackWay"+v).val()=='2'){
			$("#feedbackRate"+v).select2('destroy').empty();
			$("#feedbackRate"+v).select2({data: monthData,placeholder:'请选择',allowClear:true})
			$("#yearMonth"+v).text('每月：');
			$("#feedbackRate"+v).val("").select2({placeholder:'请选择'})
			$("#feedbackRateShow"+v).css("display","block");
		}else if($("#feedbackWay"+v).val()=='1'){
			$("#feedbackRate"+v).select2('destroy').empty();
			$("#feedbackRate"+v).select2({data: monthData,placeholder:'请选择',allowClear:true})
			$("#yearMonth"+v).text('每季度首月：');
			$("#feedbackRate"+v).val("").select2({placeholder:'请选择'})
			$("#feedbackRateShow"+v).css("display","block");
		}else{
			$('#scheBusiTaskFeedbackDataGrid'+v).dataGrid('setParam', {
				data:[]
			}, true).dataGrid('reloadGrid');
			$("#feedbackRateShow"+v).css("display","none");
		}
	}

	//根据多次反馈，反馈频次获取后台所有反馈时间段
	function getMutiFeedBackTimes(v){
		if($("#taskStartTime"+v).val()!=null&&$("#taskStartTime"+v).val()!=null&&$("#feedbackWay"+v).val()!=null&&$("#feedbackRate"+v).val()!=null){
			$.post("${ctx}/taskdeploy/dcSupTaskInfo/getMutiFeedBackTimes",{taskStartTime:$("#taskStartTime"+v).val(),taskEndTime:$("#taskEndTime"+v).val(),feedbackWay:$("#feedbackWay"+v).val(),feedbackRate:$("#feedbackRate"+v).val()},function (data){
				if(data.result == Global.TRUE){
					$('#scheBusiTaskFeedbackDataGrid'+v).dataGrid('setParam', {
						data:data.data
					}, true).dataGrid('reloadGrid');
				}else{
					js.showMessage(data.message);
				}
			});
		};
	}

</script>

<script>
	//初始化多次反馈表DataGrid对象
	$(function (){
		window.location.hash="#inputForm";
	})

	$("#scheBusiTaskFeedbackDataGrid1").dataGrid({
		data:${toJson(dcSupTaskInfo.dcSupTaskInfoAddList)} ,
		datatype: "local", // 设置本地数据
		autoGridHeight: function(){return 'auto'}, // 设置自动高度
		// 设置数据表格列
		columnModel: [
			{header:'主键', name:'id', editable:true, hidden:true},
			{header:'${text("任务表主键")}', name:'taskId', editable:true, hidden:true},
			{header:'${text("反馈开始日期")}', name:'feedbackStartTime', width:150,
				formatter:'date', formatoptions:{srcformat:'Y-m-d H:i',newformat:'Y-m-d H:i'},
				editable:true, edittype:'text',align:"center", editoptions:{'class':'form-control laydate required', 'readonly':'true',
					dataInit: function(element){
						laydate.render({elem:element, type:'datetime', format:'yyyy-MM-dd HH:mm'});
					}
				}},
			{header:'${text("反馈结束日期")}', name:'feedbackEndTime', width:150,
				formatter:'date', formatoptions:{srcformat:'Y-m-d H:i',newformat:'Y-m-d H:i'},
				editable:true, edittype:'text', align:"center",editoptions:{'class':'form-control laydate required gridDateCheck', 'readonly':'true',
					dataInit: function(element){
						laydate.render({elem:element, type:'datetime', format:'yyyy-MM-dd HH:mm'});
					}
				}},
			{header:'${text("操作")}', name:'actions', width:80, align:'center', formatter: function(val, obj, row, act){
					var actions = [];
					if (val == 'new'){
						actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#scheBusiTaskFeedbackDataGrid1\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
					}else{
						actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#scheBusiTaskFeedbackDataGrid1\').dataGrid(\'delRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
					}
					return actions.join('');
				}, editoptions: {defaultValue: 'new'}}
		],

		// 编辑表格参数
		editGrid: true,				// 是否是编辑表格
		editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
		emptyDataHint: false, 	// 表格内没有数据的时候是否提示 “无数据显示”  v4.1.7
		emptyDataHintContent: '<center>暂无数据</center>', // 没有数据的提示内容
		editGridAddRowBtn: $('#testDataChildDataGridAddRowBtn1'),	// 子表增行按钮
		editGridAddRowBtnToHeader: false,	// 子表增行按钮是否显示到表头上
		editGridAddRowInitData: {id: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

		// 编辑表格的提交数据参数
		editGridInputFormListName: 'dcSupTaskInfoAddList1', // 提交的数据列表名
		editGridInputFormListAttrs: 'id,taskId,feedbackStartTime,feedbackEndTime', // 提交数据列表的属性字段

		// 加载成功后执行事件
		ajaxSuccess: function(data){

		}
	});

	//初始化多次反馈表DataGrid对象

	$("#scheBusiTaskFeedbackDataGrid2").dataGrid({
		data:${toJson(dcSupTaskInfo.dcSupTaskInfoAddList)} ,
		datatype: "local", // 设置本地数据
		autoGridHeight: function(){return 'auto'}, // 设置自动高度
		// 设置数据表格列
		columnModel: [
			{header:'主键', name:'id', editable:true, hidden:true},
			{header:'${text("任务表主键")}', name:'taskId', editable:true, hidden:true},
			{header:'${text("反馈开始日期")}', name:'feedbackStartTime', width:150,
				formatter:'date', formatoptions:{srcformat:'Y-m-d H:i',newformat:'Y-m-d H:i'},
				editable:true, edittype:'text',align:"center", editoptions:{'class':'form-control laydate required', 'readonly':'true',
					dataInit: function(element){
						laydate.render({elem:element, type:'datetime', format:'yyyy-MM-dd HH:mm'});
					}
				}},
			{header:'${text("反馈结束日期")}', name:'feedbackEndTime', width:150,
				formatter:'date', formatoptions:{srcformat:'Y-m-d H:i',newformat:'Y-m-d H:i'},
				editable:true, edittype:'text', align:"center",editoptions:{'class':'form-control laydate required gridDateCheck', 'readonly':'true',
					dataInit: function(element){
						laydate.render({elem:element, type:'datetime', format:'yyyy-MM-dd HH:mm'});
					}
				}},
			{header:'${text("操作")}', name:'actions', width:80, align:'center', formatter: function(val, obj, row, act){
					var actions = [];
					if (val == 'new'){
						actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#scheBusiTaskFeedbackDataGrid2\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
					}else{
						actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#scheBusiTaskFeedbackDataGrid2\').dataGrid(\'delRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
					}
					return actions.join('');
				}, editoptions: {defaultValue: 'new'}}
		],

		// 编辑表格参数
		editGrid: true,				// 是否是编辑表格
		editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
		emptyDataHint: false, 	// 表格内没有数据的时候是否提示 “无数据显示”  v4.1.7
		emptyDataHintContent: '<center>暂无数据</center>', // 没有数据的提示内容
		editGridAddRowBtn: $('#testDataChildDataGridAddRowBtn2'),	// 子表增行按钮
		editGridAddRowBtnToHeader: false,	// 子表增行按钮是否显示到表头上
		editGridAddRowInitData: {id: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

		// 编辑表格的提交数据参数
		editGridInputFormListName: 'dcSupTaskInfoAddList2', // 提交的数据列表名
		editGridInputFormListAttrs: 'id,taskId,feedbackStartTime,feedbackEndTime', // 提交数据列表的属性字段

		// 加载成功后执行事件
		ajaxSuccess: function(data){

		}
	});

	//初始化多次反馈表DataGrid对象

	$("#scheBusiTaskFeedbackDataGrid3").dataGrid({
		data:${toJson(dcSupTaskInfo.dcSupTaskInfoAddList)} ,
		datatype: "local", // 设置本地数据
		autoGridHeight: function(){return 'auto'}, // 设置自动高度
		// 设置数据表格列
		columnModel: [
			{header:'主键', name:'id', editable:true, hidden:true},
			{header:'${text("任务表主键")}', name:'taskId', editable:true, hidden:true},
			{header:'${text("反馈开始日期")}', name:'feedbackStartTime', width:150,
				formatter:'date', formatoptions:{srcformat:'Y-m-d H:i',newformat:'Y-m-d H:i'},
				editable:true, edittype:'text',align:"center", editoptions:{'class':'form-control laydate required', 'readonly':'true',
					dataInit: function(element){
						laydate.render({elem:element, type:'datetime', format:'yyyy-MM-dd HH:mm'});
					}
				}},
			{header:'${text("反馈结束日期")}', name:'feedbackEndTime', width:150,
				formatter:'date', formatoptions:{srcformat:'Y-m-d H:i',newformat:'Y-m-d H:i'},
				editable:true, edittype:'text', align:"center",editoptions:{'class':'form-control laydate required gridDateCheck', 'readonly':'true',
					dataInit: function(element){
						laydate.render({elem:element, type:'datetime', format:'yyyy-MM-dd HH:mm'});
					}
				}},
			{header:'${text("操作")}', name:'actions', width:80, align:'center', formatter: function(val, obj, row, act){
					var actions = [];
					if (val == 'new'){
						actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#scheBusiTaskFeedbackDataGrid3\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
					}else{
						actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#scheBusiTaskFeedbackDataGrid3\').dataGrid(\'delRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
					}
					return actions.join('');
				}, editoptions: {defaultValue: 'new'}}
		],

		// 编辑表格参数
		editGrid: true,				// 是否是编辑表格
		editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
		emptyDataHint: false, 	// 表格内没有数据的时候是否提示 “无数据显示”  v4.1.7
		emptyDataHintContent: '<center>暂无数据</center>', // 没有数据的提示内容
		editGridAddRowBtn: $('#testDataChildDataGridAddRowBtn3'),	// 子表增行按钮
		editGridAddRowBtnToHeader: false,	// 子表增行按钮是否显示到表头上
		editGridAddRowInitData: {id: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

		// 编辑表格的提交数据参数
		editGridInputFormListName: 'dcSupTaskInfoAddList3', // 提交的数据列表名
		editGridInputFormListAttrs: 'id,taskId,feedbackStartTime,feedbackEndTime', // 提交数据列表的属性字段

		// 加载成功后执行事件
		ajaxSuccess: function(data){

		}
	});

	//初始化多次反馈表DataGrid对象

	$("#scheBusiTaskFeedbackDataGrid4").dataGrid({
		data:${toJson(dcSupTaskInfo.dcSupTaskInfoAddList)} ,
		datatype: "local", // 设置本地数据
		autoGridHeight: function(){return 'auto'}, // 设置自动高度
		// 设置数据表格列
		columnModel: [
			{header:'主键', name:'id', editable:true, hidden:true},
			{header:'${text("任务表主键")}', name:'taskId', editable:true, hidden:true},
			{header:'${text("反馈开始日期")}', name:'feedbackStartTime', width:150,
				formatter:'date', formatoptions:{srcformat:'Y-m-d H:i',newformat:'Y-m-d H:i'},
				editable:true, edittype:'text',align:"center", editoptions:{'class':'form-control laydate required', 'readonly':'true',
					dataInit: function(element){
						laydate.render({elem:element, type:'datetime', format:'yyyy-MM-dd HH:mm'});
					}
				}},
			{header:'${text("反馈结束日期")}', name:'feedbackEndTime', width:150,
				formatter:'date', formatoptions:{srcformat:'Y-m-d H:i',newformat:'Y-m-d H:i'},
				editable:true, edittype:'text', align:"center",editoptions:{'class':'form-control laydate required gridDateCheck', 'readonly':'true',
					dataInit: function(element){
						laydate.render({elem:element, type:'datetime', format:'yyyy-MM-dd HH:mm'});
					}
				}},
			{header:'${text("操作")}', name:'actions', width:80, align:'center', formatter: function(val, obj, row, act){
					var actions = [];
					if (val == 'new'){
						actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#scheBusiTaskFeedbackDataGrid4\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
					}else{
						actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#scheBusiTaskFeedbackDataGrid4\').dataGrid(\'delRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
					}
					return actions.join('');
				}, editoptions: {defaultValue: 'new'}}
		],

		// 编辑表格参数
		editGrid: true,				// 是否是编辑表格
		editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
		emptyDataHint: false, 	// 表格内没有数据的时候是否提示 “无数据显示”  v4.1.7
		emptyDataHintContent: '<center>暂无数据</center>', // 没有数据的提示内容
		editGridAddRowBtn: $('#testDataChildDataGridAddRowBtn4'),	// 子表增行按钮
		editGridAddRowBtnToHeader: false,	// 子表增行按钮是否显示到表头上
		editGridAddRowInitData: {id: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

		// 编辑表格的提交数据参数
		editGridInputFormListName: 'dcSupTaskInfoAddList4', // 提交的数据列表名
		editGridInputFormListAttrs: 'id,taskId,feedbackStartTime,feedbackEndTime', // 提交数据列表的属性字段

		// 加载成功后执行事件
		ajaxSuccess: function(data){

		}
	});

	//初始化多次反馈表DataGrid对象

	$("#scheBusiTaskFeedbackDataGrid5").dataGrid({
		data:${toJson(dcSupTaskInfo.dcSupTaskInfoAddList)} ,
		datatype: "local", // 设置本地数据
		autoGridHeight: function(){return 'auto'}, // 设置自动高度
		// 设置数据表格列
		columnModel: [
			{header:'主键', name:'id', editable:true, hidden:true},
			{header:'${text("任务表主键")}', name:'taskId', editable:true, hidden:true},
			{header:'${text("反馈开始日期")}', name:'feedbackStartTime', width:150,
				formatter:'date', formatoptions:{srcformat:'Y-m-d H:i',newformat:'Y-m-d H:i'},
				editable:true, edittype:'text',align:"center", editoptions:{'class':'form-control laydate required', 'readonly':'true',
					dataInit: function(element){
						laydate.render({elem:element, type:'datetime', format:'yyyy-MM-dd HH:mm'});
					}
				}},
			{header:'${text("反馈结束日期")}', name:'feedbackEndTime', width:150,
				formatter:'date', formatoptions:{srcformat:'Y-m-d H:i',newformat:'Y-m-d H:i'},
				editable:true, edittype:'text', align:"center",editoptions:{'class':'form-control laydate required gridDateCheck', 'readonly':'true',
					dataInit: function(element){
						laydate.render({elem:element, type:'datetime', format:'yyyy-MM-dd HH:mm'});
					}
				}},
			{header:'${text("操作")}', name:'actions', width:80, align:'center', formatter: function(val, obj, row, act){
					var actions = [];
					if (val == 'new'){
						actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#scheBusiTaskFeedbackDataGrid5\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
					}else{
						actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#scheBusiTaskFeedbackDataGrid5\').dataGrid(\'delRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
					}
					return actions.join('');
				}, editoptions: {defaultValue: 'new'}}
		],

		// 编辑表格参数
		editGrid: true,				// 是否是编辑表格
		editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
		emptyDataHint: false, 	// 表格内没有数据的时候是否提示 “无数据显示”  v4.1.7
		emptyDataHintContent: '<center>暂无数据</center>', // 没有数据的提示内容
		editGridAddRowBtn: $('#testDataChildDataGridAddRowBtn5'),	// 子表增行按钮
		editGridAddRowBtnToHeader: false,	// 子表增行按钮是否显示到表头上
		editGridAddRowInitData: {id: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

		// 编辑表格的提交数据参数
		editGridInputFormListName: 'dcSupTaskInfoAddList5', // 提交的数据列表名
		editGridInputFormListAttrs: 'id,taskId,feedbackStartTime,feedbackEndTime', // 提交数据列表的属性字段

		// 加载成功后执行事件
		ajaxSuccess: function(data){

		}
	});
	$("#taskStartTime1").val("${date(),'yyyy-MM-dd 00:00'}")
	$("#taskStartTime2").val("${date(),'yyyy-MM-dd 00:00'}")
	$("#taskStartTime3").val("${date(),'yyyy-MM-dd 00:00'}")
	$("#taskStartTime4").val("${date(),'yyyy-MM-dd 00:00'}")
	$("#taskStartTime5").val("${date(),'yyyy-MM-dd 00:00'}")
	laydate.render({
		elem: '#taskEndTime1'
		,type: 'datetime'
		,format: 'yyyy-MM-dd HH:mm'
		,done: function(value, date){
			if(value.substr(11,value.length)=='00:00'){
				$('#taskEndTime1').val(	value.substr(0,11)+"23:59")
			}
			taskTimeChange(1)
		}
	});
	laydate.render({
		elem: '#taskEndTime2'
		,type: 'datetime'
		,format: 'yyyy-MM-dd HH:mm'
		,done: function(value, date){
			if(value.substr(11,value.length)=='00:00'){
				$('#taskEndTime2').val(	value.substr(0,11)+"23:59")
			}
			taskTimeChange(2)
		}
	});
	laydate.render({
		elem: '#taskEndTime3'
		,type: 'datetime'
		,format: 'yyyy-MM-dd HH:mm'
		,done: function(value, date){
			if(value.substr(11,value.length)=='00:00'){
				$('#taskEndTime3').val(	value.substr(0,11)+"23:59")
			}
			taskTimeChange(3)
		}
	});
	laydate.render({
		elem: '#taskEndTime4'
		,type: 'datetime'
		,format: 'yyyy-MM-dd HH:mm'
		,done: function(value, date){
			if(value.substr(11,value.length)=='00:00'){
				$('#taskEndTime4').val(	value.substr(0,11)+"23:59")
			}
			taskTimeChange(4)
		}
	});
	laydate.render({
		elem: '#taskEndTime5'
		,type: 'datetime'
		,format: 'yyyy-MM-dd HH:mm'
		,done: function(value, date){
			if(value.substr(11,value.length)=='00:00'){
				$('#taskEndTime1').val(	value.substr(0,11)+"23:59")
			}
			taskTimeChange(5)
		}
	});
	$("#msgNum2").val(${dcSupTaskInfo.messageNumber})

	$(function (){
		if($('#formFlag input:radio:checked').val()=='0' || $('#formFlag input:radio:checked').val()== null){
			$('#download').hide();
		}
	})

	$('#formFlag').on('ifChecked', function(){
		// if($('#formFlag input:radio:checked').val()=='1') {
		// 	$('#download').show();
		// }else{
		//
		// }
		$('#download').hide();
	});

	$("#download").click(function (){
		var data= $('#inputForm');
		$("#messageNumber").val($("#messageNumber").val());
		$("#taskEndTime").val($("#taskEndTime").val());
		$("#taskTypeCode").val($("#taskTypeCode").select2('val'));
		$("#remarks4").val("1");
		js.ajaxSubmitForm(data,{
			url:"${ctx}/taskdeploy/dcSupTaskInfo/downLoadOversee",
			downloadFile:true
		})
	})
</script>

<script>
	function taskTimeChange(index){
		let start=$("#taskStartTime"+index).val();
		let end=$("#taskEndTime"+index).val();
		let type=$("#feedbackWay"+index).val();
		if (type=='4'&&start!=''&&end!=''){
			$("#scheBusiTaskFeedbackDataGrid"+index).jqGrid("clearGridData");
			$('#scheBusiTaskFeedbackDataGrid'+index).jqGrid('addRow', { position: 'last',
				addRowParams: {keys: false, focusField: true},
				initdata: {id: '',feedbackStartTime:start,feedbackEndTime:end, status: Global.STATUS_NORMAL}
			});
		}
	}
</script>


<script>
	$("#taskLeaderOrg1Base").click(function (){
		$("#taskLeaderOrg1Name").click()
	})
	$("#taskLeaderOrg2Base").click(function (){
		$("#taskLeaderOrg2Name").click()
	})
	$("#taskLeaderOrg3Base").click(function (){
		$("#taskLeaderOrg3Name").click()
	})
	$("#taskLeaderOrg4Base").click(function (){
		$("#taskLeaderOrg4Name").click()
	})
	$("#taskLeaderOrg5Base").click(function (){
		$("#taskLeaderOrg5Name").click()
	})
	function treeselectCallback(id, act, index, layero, nodes){
		if (act == 'clear'){
			$("#"+id+"Base").val("")
			return;
		}
		if (act=='ok'){
			let texts=""
			for (let i = 0; i <nodes.length; i++) {
				texts+=nodes[i].name+",";
			}
			if (texts.length > 0) {
				texts = texts.substr(0, texts.length - 1);
			}
			$("#"+id+"Base").val(texts)
		}
	}


</script>


<script>
	jQuery.validator.addMethod("dateCheck", function(v1,v2) {
		let id=$(v2).attr("id");
		let index=id.substr(id.length-1,1)
		let date1= $("#taskStartTime"+index).val();
		let startLogTimeDate = new Date(Date.parse(date1.replace(/-/g, "/"))).getTime();
		let date2=  $("#taskEndTime"+index).val();
		let endLogTimeDate = new Date(Date.parse(date2.replace(/-/g, "/"))).getTime();
		if(endLogTimeDate<=startLogTimeDate){
			return false;
		}else{
			return true;
		}
	}, "结束时间应大于开始时间");

	jQuery.validator.addMethod("gridDateCheck", function(v1,v2) {
		let prefixId= $(v2).attr("rowid")
		let statId= prefixId+"_feedbackStartTime";
		let endId= prefixId+"_feedbackEndTime";
		let date1= $("#"+statId).val();
		let startLogTimeDate = new Date(Date.parse(date1.replace(/-/g, "/"))).getTime();
		let date2=  $("#"+endId).val();
		let endLogTimeDate = new Date(Date.parse(date2.replace(/-/g, "/"))).getTime();
		if(endLogTimeDate<=startLogTimeDate){
			return false;
		}else{
			return true;
		}
	}, "结束时间应大于开始时间");

	changeOne();
	function changeOne() {
		var msgNum = $('#msgNum').val();
		//	msgNum = msgNum.substring(0,msgNum.indexOf('〔'))
		$.ajax({
			type: 'get',
			url: "${ctx}/taskdeploy/dcSupTaskInfo/getMaxMessageNumberByType?msgNum="+msgNum,
			success: function (res) {
				$('#msgNum2').val(Number(res.data.msgNum2)+1);
			}
		})
	}
</script>